# -*- coding: utf-8 -*-
"""
@Time: 2024/12/31 14:55
@Author: Mr.Z
@contact: <QQ:40061980>
@contact: bob@pheks.com
@File: about.py
@IDE: PyCharm
@Python Version: 3.x
"""
from PySide6.QtCore import QUrl
from PySide6.QtGui import QPixmap, QDesktopServices, QIcon
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton
from PySide6.QtCore import Qt  # 引入Qt模块以使用对齐方式


class AboutWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("关于")  # 设置窗口标题
        self.setFixedSize(300, 200)  # 设置窗口固定大小
        self.setWindowIcon(QIcon("./static/image/logo.png"))  # 设置窗口图标

        # 创建主布局
        main_layout = QHBoxLayout(self)

        # 添加logo
        logo_label = QLabel(self)
        pixmap = QPixmap("./static/image/logo.png")
        logo_label.setPixmap(pixmap.scaledToWidth(64))
        main_layout.addWidget(logo_label, alignment=Qt.AlignLeft)  # 将logo放在左侧

        # 创建文字信息布局
        info_layout = QVBoxLayout()

        # 添加关于信息
        self.add_info_label(info_layout, "鼠标连点器 v1.0\n作者：Mr. Z\n联系方式：bob@pheks.com\n")
        self.add_link_button(info_layout, "官方网站：www.pheks.com", "https://www.pheks.com")
        self.add_info_label(info_layout, "鼠标连点器是一个开源软件，使用PySide6开发，遵循AGPL-3.0协议。")
        self.add_info_label(info_layout, "深圳市飞可思信息通信技术有限公司")

        # 将文字信息布局添加到主布局
        main_layout.addLayout(info_layout)

        # 设置窗口居中
        self.center_on_screen()

    @staticmethod
    def add_info_label(layout, text):
        """用于向布局添加信息标签"""
        label = QLabel(text, parent=layout.parent())
        label.setWordWrap(True)
        layout.addWidget(label)

    @staticmethod
    def add_link_button(layout, display_text, url):
        """用于向布局添加可点击链接按钮"""
        button = QPushButton(display_text, parent=layout.parent())
        button.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(url)))
        layout.addWidget(button)

    def center_on_screen(self):
        """获取屏幕尺寸并居中显示"""
        screen_geometry = QApplication.screenAt(self.geometry().center()).availableGeometry()
        x = (screen_geometry.width() - self.width()) // 2
        y = (screen_geometry.height() - self.height()) // 2
        self.move(x, y)


# if __name__ == "__main__":
#     app = QApplication([])
#
#     about_window = AboutWindow()
#     about_window.show()

#     app.exec()
